Skip to content

Comments

Support new forecasting endpoints (/sensors/{id}/forecasts/trigger and /sensors/{id}/forecasts/{uuid})#180

Open
Copilot wants to merge 6 commits intomainfrom
copilot/support-forecasting-endpoints
Open

Support new forecasting endpoints (/sensors/{id}/forecasts/trigger and /sensors/{id}/forecasts/{uuid})#180
Copilot wants to merge 6 commits intomainfrom
copilot/support-forecasting-endpoints

Conversation

Copy link
Contributor

Copilot AI commented Feb 23, 2026

FlexMeasures server v0.31.0 introduced POST /sensors/{id}/forecasts/trigger and GET /sensors/{id}/forecasts/{uuid} for async forecast job execution. This adds client-side support for both, along with documentation and agent instructions.

New Methods

  • trigger_forecast(sensor_id, ...) — POSTs to /sensors/{id}/forecasts/trigger, returns forecast job UUID. Training params (train_start, train_period, retrain_frequency, regressors, etc.) are serialized into a nested config dict per the server schema.
  • get_forecast(sensor_id, forecast_id) — GETs /sensors/{id}/forecasts/{uuid}, polling on 202 until the job completes (200). Returns {values, start, duration, unit}.
  • trigger_and_get_forecast(sensor_id, ...) — Convenience wrapper combining both.

Usage

# Trigger and poll until complete (minimal)
forecast = await client.trigger_and_get_forecast(
    sensor_id=5,
    duration="PT24H",
)

# With advanced options
forecast = await client.trigger_and_get_forecast(
    sensor_id=5,
    start="2025-01-05T00:00:00+00:00",
    end="2025-01-07T00:00:00+00:00",
    train_start="2025-01-01T00:00:00+00:00",
    retrain_frequency="PT24H",
    future_regressors=[2, 3],
)
# {"values": [...], "start": "...", "duration": "PT48H", "unit": "kW"}

# Or step-by-step
forecast_id = await client.trigger_forecast(sensor_id=5, start="...", end="...")
forecast = await client.get_forecast(sensor_id=5, forecast_id=forecast_id)

Requires FlexMeasures server ≥ 0.31.0. get_forecast respects the client's existing polling_timeout, polling_interval, and max_polling_steps settings.

Documentation

  • Added a Forecasting section to README.rst with a minimal trigger_and_get_forecast example and a cross-reference to docs/forecasting.rst.
  • Created docs/forecasting.rst with advanced examples covering: forecast window, training config, regressors, step-by-step usage, and polling behaviour.
  • Added docs/forecasting.rst to the docs/index.rst toctree.

Agent Instructions

  • Created .github/agents/copilot.md with repo-specific instructions covering tests, linting, coding patterns, and delegation to the test-specialist sub-agent.
Original prompt

This section details on the original issue you should resolve

<issue_title>Support new forecasting endpoints</issue_title>
<issue_description>New forecasting API endpoints were introduced in the FlexMeasures server: [POST] /sensors/(id)/forecasts/trigger <api/v3_0.html#post--api-v3_0-sensors-id-forecasts-trigger>_ and [GET] /sensors/(id)/forecasts/(uuid) <api/v3_0.html#get--api-v3_0-sensors-id-forecasts-uuid>_ to forecast sensor data [see PR FlexMeasures/flexmeasures-client#1813 <https://www.github.com/FlexMeasures/flexmeasures/pull/1813>, PR FlexMeasures/flexmeasures-client#1823 <https://www.github.com/FlexMeasures/flexmeasures/pull/1823> and PR FlexMeasures/flexmeasures-client#1917 <https://www.github.com/FlexMeasures/flexmeasures/pull/1917>_]. We need to support these endpoints in the FlexMeasures client.</issue_description>

<agent_instructions>Make sure to use #1917 for the latest schema versions! And call the test-specialist as a sub-agent in your task. Make sure the test-specialist actually creates new tests and, super important, runs them successfully (not just says it ran them successfully by inspecting code).</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 23, 2026 19:26
Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
…ecast

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copilot AI changed the title [WIP] Support new forecasting API endpoints in client Support new forecasting endpoints (/sensors/{id}/forecasts/trigger and /sensors/{id}/forecasts/{uuid}) Feb 23, 2026
Copilot AI requested a review from Flix6x February 23, 2026 19:35
@Flix6x
Copy link
Contributor

Flix6x commented Feb 24, 2026

@copilot fix your linting and verify tests pass before asking for any review. Also create or update your agent instructions for this repo accordingly.

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@copilot fix your linting and verify tests pass before asking for any review. Also create or update your agent instructions for this repo accordingly.

Fixed a black formatting issue in client.py (commit 0fea65b). All 35 tests pass and black/flake8/isort all pass cleanly.

Also created .github/agents/copilot.md with repo-specific agent instructions covering: running tests, linting workflow, coding patterns for new API methods, polling patterns, and notes on the forecasting endpoints added in this PR.

@Flix6x
Copy link
Contributor

Flix6x commented Feb 24, 2026

@BelhsanHmida could you please test out the three new client methods implemented in this PR, against a local FlexMeasures server?

@copilot please add a simple example of the client.trigger_and_get_forecast method to the README.md (maybe with only a sensor ID and an optional duration), together with a cross-reference to a new /docs/forecasting.rst with a few more advanced examples. Also note the existence of .github/agents/test-specialist.md and update (simplify) your agent instructions to make use of this specialist as a sub-task. Note that it remains your job to check that the test-specialist actually did its job and ran precommit hooks and tests.

… copilot agent instructions

Co-authored-by: Flix6x <30658763+Flix6x@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 24, 2026

@BelhsanHmida could you please test out the three new client methods implemented in this PR, against a local FlexMeasures server?

@copilot please add a simple example of the `clie...

Done in commit 9f0766b:

  • Added a Forecasting section to README.rst with a minimal trigger_and_get_forecast example (sensor ID + duration) and a cross-reference to the new docs page.
  • Created docs/forecasting.rst with sections covering: basic usage, specifying a forecast window, controlling the training window, using regressors, step-by-step (separate trigger + get), and polling behaviour settings.
  • Added forecasting.rst to the docs/index.rst toctree.
  • Simplified .github/agents/copilot.md — it now delegates test writing to the test-specialist sub-agent and explicitly calls out that I must verify the sub-agent's work by running pytest and linting checks myself.

@Flix6x Flix6x marked this pull request as ready for review February 24, 2026 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support new forecasting endpoints

2 participants